package com.timeriver.utils;

import com.timeriver.domain.ResponseEnum;
import com.timeriver.domain.ResponseObj;

public class ResponseUtil {
    /**
     * 包含对象信息的成功响应
     * @param data
     * @return
     */
    public static ResponseObj success(Object data){
        return success(ResponseEnum.SUCCESS.getMsg(), data);
    }

    /**
     * 没有对象信息的成功响应
     * @return
     */
    public static ResponseObj success(){
        return success(null);
    }

    public static ResponseObj success(String message, Object data) {
        ResponseObj resultData = new ResponseObj();

        resultData.setData(data);
        resultData.setCode(ResponseEnum.SUCCESS.getCode());
        resultData.setMsg(message);

        return resultData;
    }

    public static ResponseObj error(Integer code, String msg){
        ResponseObj resultData = new ResponseObj();

        resultData.setCode(code);
        resultData.setMsg(msg);

        return resultData;
    }

    public static ResponseObj error(){
        return error(ResponseEnum.FAILED.getCode(), ResponseEnum.FAILED.getMsg());
    }

    public static ResponseObj error(String msg){
        return error(ResponseEnum.FAILED.getCode(), msg);
    }
}
